package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.model.media.pojo.WmUser;
import com.heima.wemedia.service.WmUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "WemediaDto",tags = "自媒体管理Api")
@RestController
@RequestMapping("/api/v1/user")
public class WmUserController {

    @Autowired
    private WmUserService wmUserService;
    @ApiOperation("保存自媒体用户")
    @PostMapping("/save")
    public WmUser save(@RequestBody WmUser wmUser){
        this.wmUserService.save(wmUser);
        return wmUser;  //返回用户wmUser
    }
    @ApiOperation("按照名称查询用户")
    @GetMapping("/findByName/{name}")
    public WmUser findUserByname(@PathVariable("name") String name){
        LambdaQueryWrapper<WmUser> lambdaQueryWrapper = Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name);
        return this.wmUserService.getOne(lambdaQueryWrapper);
    }
    @ApiOperation("按照id查询用户")
    @GetMapping("/findOne/{id}")
    public WmUser findWmUserById(@PathVariable("id")Integer id){
        return this.wmUserService.getById(id);
    }
}
